package utils.global.fliters;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "myXssFilter", urlPatterns = "/*")
public abstract class XssFliterConfig implements Filter {

    private FilterConfig filterConfig = null;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        filterChain.doFilter(new BaseXssRequesterWapper((HttpServletRequest) servletRequest) {
            @Override
            public String afterCleanXSS(String value) {
                return cleanXSS(value);
            }
        }, servletResponse);
    }

    @Override
    public void destroy() {
        this.filterConfig = null;
    }

    public abstract String cleanXSS(String value);
}
